﻿using Volo.Abp.Auditing;
using Volo.Abp;
using Volo.Abp.Autofac;
using Volo.Abp.Modularity;
using Volo.Abp.Swashbuckle;
using Microsoft.AspNetCore.Builder;

namespace SqlSugarApi
{
    [DependsOn(
    typeof(AbpAutofacModule),
    typeof(Nuctech.ACCT.OIS.SqlSugar.NuctechSqlSugarModule),
    typeof(AbpSwashbuckleModule)
    )]
    public class SqlSugarApiModule : AbpModule
    {
        public override void PreConfigureServices(ServiceConfigurationContext context)
        {

        }

        /// <summary>
        /// 添加服务
        /// </summary>
        /// <param name="context"></param>
        public override void ConfigureServices(ServiceConfigurationContext context)
        {
            var hostingEnvironment = context.Services.GetHostingEnvironment();
            var configuration = context.Services.GetConfiguration();

            // Add services to the container.

            context.Services.AddControllers();
            // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
            context.Services.AddEndpointsApiExplorer();
            context.Services.AddSwaggerGen();
        }

        /// <summary>
        /// 初始化中间件
        /// </summary>
        /// <param name="context"></param>
        public override void OnApplicationInitialization(ApplicationInitializationContext context)
        {
            var app = context.GetApplicationBuilder();
            var env = context.GetEnvironment();

            // Configure the HTTP request pipeline.
            if (env.IsDevelopment())
            {
                app.UseSwagger();
                app.UseSwaggerUI();
            }

            app.UseAuthorization();


            // 静态文件中间件
            app.UseStaticFiles();


            // 路由中间件
            app.UseRouting();


            app.UseConfiguredEndpoints();
        }

    }
}
